package com.xuyiwei.mayi.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by xuyiwei on 2019/4/13.
 */
public class JDKProxy implements InvocationHandler {
    private Object target;
    public JDKProxy(Object target) {
        this.target = target;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("JDK动态代理开始");
        Object o = method.invoke(target,args);
        System.out.println("JDK动态代理结束");
        return o;
    }
    public static void main(String[] args) {
        HoseImpl imp = new HoseImpl();
        JDKProxy proxy = new JDKProxy(imp);
        Hose hose = (Hose) Proxy.newProxyInstance(imp.getClass().getClassLoader(),imp.getClass().getInterfaces(),proxy);
        hose.mai();
    }
}
